<!-- 新建模型配置 -->
<template>
	<div>
		<el-form :model="editForm" ref="editForm" :rules="rules" >
			<el-form-item label="模型名称" prop="model_name">
				<el-input v-model="editForm.model_name" clearable placeholder="请输入模型名称" size="small"></el-input>
			</el-form-item>
			<el-form-item label="备注" prop="comment">
				<el-input v-model="editForm.comment" clearable placeholder="请输入备注" size="small"></el-input>
			</el-form-item>
		</el-form>
		<div class="dialog-footer">
			<el-button @click="closedialog">取 消</el-button>
			<el-button type="primary" @click="saveEdit">确 定</el-button>
		</div>
	</div>
</template>

<script>
import {editModelAPI,addModelAPI,} from '@/api/index';

export default {
	name: 'editModel',
	props: {
		Infoitem: Object
	},
	data() {
	    return {
			title:'',
			editForm:{},
			rules: {
				model_name: [{ required: true, message: '请输入模型名称', trigger: 'blur' }]
			},
	    };
	},
	mounted() {
		if(JSON.stringify(this.Infoitem) !== '{}'){
			this.editForm = this.Infoitem
		}
	},
	methods:{
		saveEdit(){
			var that = this
			that.$refs.editForm.validate(valid => {
			    if (valid) {
					if(that.editForm.model_id){
						editModelAPI(that.editForm).then(res => {
							if(res.status == 200){
								that.$message.success(`修改成功`);
								that.closedialog();
							}else{
								that.$message.error(res.msg);
							}
						});
					}else{
						addModelAPI(that.editForm).then(res => {
							if(res.status == 200){
								that.$message.success(`添加成功`);
								that.closedialog();
							}else{
								that.$message.error(res.msg);
							}
						});
					}
			    } else {
			        console.log('error submit!!');
			        return false;
			    }
			});
		},
		closedialog() {
			this.$emit('closeDialog', false);
		}
	}
};
</script>

<style scoped>
.dialog-footer {
	width: 100%;
	text-align: right;
}
/deep/.el-col-12{
	padding: 0 15px;
}
</style>
